From http://cscircles.cemc.uwaterloo.ca/2-functions/:

In this assignment we are asked to calculate the maximum weight of a truck which can cross the bridges. If we think logically, about it, we decide that it must be the minimum of the weight limits a, b, and c.
<img src="https://raw.githubusercontent.com/pbeens/ICS-Computer-Studies/master/Python/Class%20Demos/files/cscircles_one_road.png", width=50%,height=50%>

Luckily, Python has a min() function we can use to make this task easy. If we assign the values of a, b, and c, we can quickly determine the minumum of the three:


In [1]:
a = 1000
b = 2340
c = 3246
print ('The weight limit for this path is', min(a, b, c), 'units.')


The weight limit for this path is 1000 units.

So the maximum weight of a truck crossing the bridges can only be 1000 units (kg, lbs, etc.).

Now what about this example where we have two routes we can take?

<img src="https://raw.githubusercontent.com/pbeens/ICS-Computer-Studies/master/Python/Class%20Demos/files/cscircles_two_roads.png", width=50%, height=50%>

In this case we want to take the maximum of the two mimimums.

Let's start by setting the values of all the weight limits:


In [2]:
a = 1000
b = 2340
c = 3246
d = 1400
e = 5000

Then let's create two variables to represent the maximum weight for each of the two paths, which, don't forget, has to be the minimum of the values of the two paths.


In [3]:
path_1_limit = min(a, b, c)
path_2_limit = min(d, e)
print ('The 1st path limit is', path_1_limit, 'and the 2nd path limit is', path_2_limit)


The 1st path limit is 1000 and the 2nd path limit is 1400

The maximum weight limit would obviously be 1400 units, which is the maximum of our two values. Using the max() function we have:


In [4]:
print ('The maximum weight that be carried is', max(path_1_limit, path_2_limit), 'units.')


The maximum weight that be carried is 1400 units.